package com.github.codemperor.core;

import com.github.codemperor.core.async.AsyncConfig;
import com.github.codemperor.core.async.AsyncConst;
import com.github.codemperor.core.feign.FeignInterceptor;
import com.github.codemperor.core.oss.OssConfig;
import com.github.codemperor.core.token.aop.UserInfoAop;
import com.github.codemperor.core.util.PropertyUtils;
import com.github.codemperor.core.util.SpringContextUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * 所有核心配置的孵化工厂
 *
 * @author codemperor
 */
@Configuration
@EnableAsync
public class CoreFactory {

    @Bean(AsyncConst.UPTRADE_ASYNC_THREAD_NAME)
    public AsyncTaskExecutor asyncConfig() {
        AsyncConfig asyncConfig = new AsyncConfig();
        return asyncConfig.taskExecutor();
    }

    /**
     * 登陆用户信息的aop。默认开启，可以通过uptrade.aop.enabled=false关闭
     *
     * @return
     */
    @Bean
    public UserInfoAop currentUserAop() {
        return new UserInfoAop();
    }

    /**
     * 登陆用户信息的aop。默认开启，可以通过uptrade.aop.enabled=false关闭
     *
     * @return
     */
    @Bean
    public FeignInterceptor feignInterceptor() {
        return new FeignInterceptor();
    }

    /**
     * oss
     */
    @Bean
    public OssConfig ossConfig() {
        return new OssConfig();
    }

    /**
     * 配置文件
     *
     * @return
     */
    @Bean
    public PropertyUtils propertyUtils() {
        return new PropertyUtils();
    }

    /**
     * spring上下文
     *
     * @return
     */
    @Bean
    public SpringContextUtil springContextUtil() {
        return new SpringContextUtil();
    }

}
